<?php
class Form_Account extends Zend_Form {
    
    protected $_email = null;

    public function __construct($email = null) {
        $this->_email = $email;
       // echo $this->_email;die;
        parent::__construct();
    }

     public function init() {
     parent::init();
     $this->setAction('/account/edit');
     $this->setMethod('post');
     $this->setAttrib('class', 'account');

     $email = new Form_Element_Email('email');
     $email->addValidator('Db_NoRecordExists', true, array('users', 'email', array('field'=>'email','value'=>$this->_email)));
     $this->addElement($email);

     $name = new Form_Element_Name('name');
     $this->addElement($name);

     $password = new Form_Element_Password('password');
     $this->addElement($password);

     $location = new Form_Element_Location('location');
     $this->setAttrib('required', true);
     $this->addElement($location);
     
     $privacy = new Zend_Form_Element_Select('privacy', array(
        'label'       => 'Make your places visible only for you?',
        'multiOptions'=> array('choose...', 'public', 'private'),
        'filters'     => array('Alnum'),
     ));
     $this->addElement($privacy);
     
     $sex = new Zend_Form_Element_Radio('sex', array(
        'label'       => 'Sex:',
        'multiOptions'=> array('m' => 'Male', 'f' => 'Female'),
        'validators'  => array(array('InArray', true, array(array('m', 'f'), true)))
     ));
     $sex->setSeparator(' ');
     $this->addElement($sex);
     $age = new Zend_Form_Element_Select('age', array(
        'label'       => 'Age:',
        'multiOptions'=> array('', '11 - 20', '21 - 30', '31 - 40'),
        'filters'     => array('Int'),
     ));
     $this->addElement($age);

     $about = new Zend_Form_Element_Textarea('about', array(
        'label'       => 'A few words about:',
        'rows'        => '5',
        'cols'        => '45',
        'validators'  => array(
            array('StringLength', true, array(0, 5000))
         ),
        'filters'     => array('StringTrim'),
     ));
     $this->addElement($about);
    
     $submit = new Zend_Form_Element_Submit('submit', array(
         'label' => 'Save',
     ));      
     $this->addElement($submit);

     $this->addDisplayGroup(
         array('name', 'email', 'location', 'privacy', 'password', 'sex', 'age', 'about', 'submit'), 'accountDataGroup',
         array(
             'legend' => 'Edit Account'
         )
     );
    }
}